<?php

class Static_Backend_Contents_Edit extends Kernel_Action_Form_Simple
{
    
    /**
     * Путь к файлу шаблона.
     *
     * @var string
     */
    protected $_template = 'static/backend/container.tpl';
    
    /**
     * Таблица, в которой хранится редактируемый элемент.
     *
     * @var string
     */
    protected $_table = 'system_contents';

    /**
     * Initialize form elements. 
     *
     */
    protected function _initElements()
    {
        parent::_initElements();
        
        $this->_setElementParam('contents', 'template', 'wysiwyg');
        $this->_setAsRequired();
    }
    
    /**
     * Реализация обработки пользовательского запроса.
     *
     */
    protected function _process() 
    {
        $exclude_actions = (array)Kernel_Config::get('Static', 'exclude_actions');
        
        if ('add' != Application::getRequest()->get('action') &&
            !in_array('delete', $exclude_actions)) 
        {
            Application::getResponse()->assign(array('buttons' => array(
                'delete' =>
                    Backend_Filter_Structure::get(array()) + 
                    array('action' => 'delete', 'id' => $this->id), 
                )));
        }
        
        parent::_process();
    }
    
    /**
     * Add new record.
     *
     */
    protected function _insert() 
    {
        parent::_insert();
        
        database::insert('static', array('contents_id' => $this->id));
    }
    
}
